Skip to content

perf(lingbot): enable rms_affine modulation fusion - #2422

Open
losewayy wants to merge 1 commit into
leejet:masterfrom
losewayy:perf/lingbot-modulation-fusion
Open

losewayy wants to merge 1 commit into
leejet:masterfrom
losewayy:perf/lingbot-modulation-fusion

Conversation

@losewayy

@losewayy losewayy commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enable the existing rms_affine modulate and residual fusions in LingBotVideo:

  • Keep the timestep embedding broadcastable across tokens instead of expanding it with ggml_repeat, and call ctx->expand_graph(temb6) so timestep ops stay outside the first block's fusion pattern.
  • Swap the ggml_mul operand order on gated residuals to match the fused residual pattern.
  • Pass gf to get_context(gf) so graph expansion is wired up.

Related Issue / Discussion

N/A

Additional Information

Tested on Windows with an RTX 5070 Ti Laptop GPU and CUDA 13.4 using lingbot-video-dense-1.3b.safetensors, Qwen3-VL-4B-Instruct-Q4_K_M, and Wan 2.1 VAE at 512x288, 17 frames, CFG 3, seed 42, with --offload-to-cpu --vae-tiling.

  • Across three interleaved 10-step runs, mean sampling time dropped from 7.68 s to 6.19 s, steady-state throughput rose from 1.66 it/s to 2.04 it/s, and the DiT CUDA compute workspace dropped from 514.41 MB to 287.44 MB.
  • On a 20-step run using the documented cat prompt, sampling time dropped from 17.06 s to 12.96 s with visually matching output frames, PSNR 39.91 dB and mean pixel difference 1.01 / 255.
  • Under nsys on a 3-step CFG run, all 288 sd_rms_affine modulate and 288 residual kernels fired, removing 576 standalone rms_norm_f32 and 288 gate mul launches.

LingBot MoE 30B shares LingBotBlock but was not tested with real weights due to local disk and VRAM limits; Vulkan and Metal were not tested.

Checklist

Summary by CodeRabbit

  • Bug Fixes
    • Video generation now applies timestep conditioning consistently across tokens and incorporates attention and feed-forward gating in the updated order.
    • These adjustments improve consistency in how video model outputs are computed.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

LingBot Video now uses a single timestep embedding per batch for modulation, applies gates to attention and FFN outputs, and passes the graph to the runner context lookup.

Changes: LingBot Video Forward Pass

Layer / File(s) Summary
Modulation and graph construction
src/model/diffusion/lingbot_video.hpp
temb6 uses a one-token shape and is expanded into the graph before the block loop. Attention and FFN outputs are multiplied by their gates. build_graph calls get_context(gf).

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Refactor

Suggested reviewers: leejet

Merge Risk: Minimal · up to 25157

This change enables existing fused modulation kernels in LingBot Video to reduce sampling time and memory. No concrete correctness or stability defect was found. The author reports matching output on CUDA. The MoE variant, Vulkan and Metal were not tested, which is ordinary residual uncertainty.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: enabling rms_affine modulation fusion for LingBot video, under a perf() prefix. The raw summary shows changes to LingBot block modulation, timestep embedding handling,…
Description check Passed The description follows the template's main sections: Summary, Related Issue / Discussion, Additional Information, and Checklist. The Summary explains what changed and why. The Related Issue section s…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: enabling rms_affine modulation fusion for LingBot video, under a perf() prefix. The raw summary shows changes to LingBot block modulation, timestep embedding handling, and get_context(gf), which match the title's focus on fusion. The title does not mention the operand order swap or the get_context change, but it does not need to cover every detail.

Full details: Description check

Explanation

The description follows the template's main sections: Summary, Related Issue / Discussion, Additional Information, and Checklist. The Summary explains what changed and why. The Related Issue section says N/A. The Additional Information section gives detailed test notes and limits. The checklist has the contribution guidelines item checked. The template's model documentation checklist item is absent. That item applies only if the PR adds or changes model support, and this PR changes performance code paths, so the omission is minor.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: db72b383-7fba-4dc0-acb9-b7a13cf19f9e
Commits

Reviewing files that changed from the base of the PR and between 5fa203c and 2515763.

Files selected for processing: 1

  • src/model/diffusion/lingbot_video.hpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant